﻿import QtQuick 2.0
import QtQuick.Window 2.12
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.12
import "../components"


Item {

    id: settingsModel
    anchors.fill: parent

    BoxModelFilter{
        id: box_modelFilter
        visible: false
        z: 1
    }

    property var tableTitle: ["序号", "基因分析仪", "试剂盒类型", "试剂盒名称", "体系(μl)", "创建时间", "备注", "操作"]

    property var ruleInfo: ({
                                "Jyfxy": "全部",
                                "ReagentKitType": "全部",
                                "ReagentKitName": "全部",
                                "System": "全部",
                                "starttime": "2024-01-01",
                                "endtime": "2024-12-31"
                            })

    function refresh(){
        var res = CSetUp.queryModelInfo(ruleInfo)
        listModel.clear()
        for(let i = 0; i < res.length; i ++){
            listModel.append({
                                 "modelId": res[i]["ID"],
                                 "modelSerial": i+1,
                                 "modelGeneAnalyzer": res[i]["GeneticAnalysers"],
                                 "modelKitType": res[i]["ReagentKitType"],
                                 "modelKitName": res[i]["ReagentKitName"],
                                 "modelSystem": res[i]["System"],
                                 "modelCreateTime": res[i]["CreateTime"],
                                 "modelMemo": res[i]["Memo"]
                             })
        }
    }
    function delModel(modelId){
        delModelId = modelId
        box_delModel.show()
    }

    onVisibleChanged: {
        pswd.visible = true
        if(!visible) return
        refresh()
    }

    property var delModelId: ""
    BoxWarning{
        id: box_delModel
        box_text: "确认删除吗?"
        onAccept: {
            CSetUp.delModel(delModelId)
            refresh()
        }onReject: {

        }
    }
    BoxHHPD{
        id: box_hhpd
    }
    BoxPSWD{
        id: box_pswd
    }



    clip: true
    // 上面的按钮
    Row{
        y: 20*dp
        x: parent.width - 560*dp
//        x: parent.width - 420*dp
        spacing: 20*dp
        width: 560*dp
        height: 40*dp

        PushButton{
            title: "导入模型"
            defaultMode1: true
            onReleased: {
                CSetUp.importModel()
                refresh()
            }
        }PushButton{
            title: "混合判定"
            defaultMode2: true
            onReleased: {
                box_hhpd.show()
            }
        }PushButton{
            title: "修改密码"
            defaultMode2: true
            onReleased: {
                box_pswd.show()
            }
        }PushButton{
            title: "筛选"
            defaultMode2: true
            onReleased: {
                box_modelFilter.visible = true
            }
        }

    }


    // 下面的表格
    // 表头
    Row{
        y: 80*dp
        x: 20*dp
        spacing: 0
        height: 60*dp
        Repeater{
            model: 8
            Rectangle{
                height: 60*dp
                width: index === 0 ? settingsModel.width/8-70*dp : (index === 5 ? settingsModel.width/8+30*dp : settingsModel.width/8)
                color: "#F7F8FA"
                Text{
                    text: tableTitle[index]
                    font.pixelSize: config.fontsize
                    anchors.centerIn: parent
                    font.bold: true
                }
            }
        }
    }
    // 表格
    ListView{
        id: listView
        model: listModel
        x: 20*dp
        y: 140*dp
        height: parent.width - 160*dp
        width: settingsModel.width - 40*dp
        clip: true
        delegate: listComponent
        ScrollBar.vertical: ScrollBar{}
    }
    Component{
        id: listComponent
        Rectangle{
            color: "#EBEDF0"
            height: 50*dp
            width: settingsModel.width - 40*dp
            Row{
                x: 1
                spacing: 1
                Rectangle{
                    height: 50*dp - 1
                    width: settingsModel.width/8 - 70*dp - 1
                    Text{
                        text: modelSerial
                        font.pixelSize: config.fontsize
                        anchors.centerIn: parent
                    }
                }Rectangle{
                    height: 50*dp - 1
                    width: settingsModel.width/8 - 1
                    Text{
                        text: modelGeneAnalyzer
                        font.pixelSize: config.fontsize
                        anchors.centerIn: parent
                    }
                }Rectangle{
                    height: 50*dp - 1
                    width: settingsModel.width/8 - 1
                    Text{
                        text: modelKitType
                        font.pixelSize: config.fontsize
                        anchors.centerIn: parent
                    }
                }Rectangle{
                    height: 50*dp - 1
                    width: settingsModel.width/8 - 1
                    Text{
                        text: modelKitName
                        font.pixelSize: config.fontsize
                        anchors.centerIn: parent
                    }
                }Rectangle{
                    height: 50*dp - 1
                    width: settingsModel.width/8 - 1
                    Text{
                        text: modelSystem
                        font.pixelSize: config.fontsize
                        anchors.centerIn: parent
                    }
                }Rectangle{
                    height: 50*dp - 1
                    width: settingsModel.width/8 - 1 + 30*dp
                    Text{
                        text: modelCreateTime
                        font.pixelSize: config.fontsize
                        anchors.centerIn: parent
                    }
                }Rectangle{
                    height: 50*dp - 1
                    width: settingsModel.width/8 - 1
                    Text{
                        text: modelMemo
                        font.pixelSize: config.fontsize
                        anchors.centerIn: parent
                    }
                }Rectangle{
                    height: 50*dp - 1
                    width: settingsModel.width/8 - 2
                    Text{
                        text: "删除"
                        color: "#1677FF"
                        font.pixelSize: config.fontsize
                        anchors.centerIn: parent
                    }
                    MouseArea{
                        anchors.centerIn: parent
                        height: 30*dp
                        width: 50*dp
                        cursorShape: Qt.PointingHandCursor
                        onReleased: {
                            delModel(modelId)
                        }
                    }
                }
            }
        }
    }

    ListModel{
        id: listModel
    }

    CustomPassword{
        id: pswd
        pstype:0
    }

}
